package com.zm.se.controller;

import com.zm.se.service.EquService.ex.*;
import com.zm.se.service.managerService.ex.*;
import com.zm.se.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {



    /**
     * 自动捕获异常并处理异常
     * @param e 异常的大爹，能转换成他就代表这个异常它能够处理
     * @return
     */
    @ExceptionHandler(ServiceException.class)
    public JsonResult<Void> handleException(Throwable e){
        JsonResult<Void> json=new JsonResult<>(e);
        if (e instanceof UserNameDuplicateException){
            json.setState(3000);
        }else if(e instanceof FileTypeException){
            json.setState(2000);
        }else if(e instanceof FileUploadException){
            json.setState(2001);
        }else if(e instanceof InsertException){
            json.setState(4000);
        }else if(e instanceof NoEmpException){
            json.setState(5000);
        }else if(e instanceof ManagerNotFoundException){
            json.setState(50001);
        }else if (e instanceof CheckException){
            json.setState(6000);
        }else if(e instanceof BorrowException){
            json.setState(7000);
        }else if(e instanceof UnderStockException){
            json.setState(8000);
        }else if(e instanceof PasswordMisMatchException){
            json.setState(9000);
        }else if(e instanceof UpdateException){
            json.setState(10000);
        }else if (e instanceof ReturnOutofNumberException){
            json.setState(12700);
        }
        return json;
    }
}
